package org.yar.common;

/*
 * Old color picker preference, not used anymore.
 * Kept around for future reference
 */
import org.yar.R;
import org.yar.views.ColorPickerView;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

public class ColorPreference extends DialogPreference {

	private ColorPickerView cpv;
	private ImageView color;
	
	public ColorPreference(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		
		setWidgetLayoutResource(R.layout.color_preference_widget);
	}

	public ColorPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		setWidgetLayoutResource(R.layout.color_preference_widget);
	}

	@Override
	protected void onBindView(View v)
	{
		super.onBindView(v);
		
		color = (ImageView)v.findViewById(R.id.color);
		color.setImageDrawable(new ColorDrawable(getPersistedInt(Color.BLACK)));
	}
	
	

	@Override
	protected View onCreateDialogView() {
		cpv = new ColorPickerView(getContext(), getPersistedInt(Color.BLACK));
		return cpv;
	}

	@Override
	protected void onDialogClosed(boolean positiveResult) {
		if (positiveResult)
		{
			color.setImageDrawable(new ColorDrawable(cpv.getColor()));
			getEditor().putInt(getKey(), cpv.getColor()).commit();
		}
	}

	
	
	
}
